const Mock = require('mockjs')

const data = Mock.mock({
  'items|12': [{
    id: '@id',
    account: '@integer(10, 1000000)',
    userName: '@name',
    position: '@integer(10, 50)',
    telephone: /^1[34578]\d{9}$/,
    statusFlag: '@boolean',
    lockTime: '@datetime'
  }]
})
module.exports = [
  {
    url: '/accountUnlockLing/page',
    type: 'get',
    response: (config) => {
      const { items } = data
      const { pageNo = 1, pageSize = 10 } = config.query
      const pageList = items.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: '00000',
        data: {
          totalRows: items.length,
          rows: pageList
        }
      }
    }
  },
  {
    url: '/accountUnlockLing/unlock',
    type: 'post',
    response: (config) => {
      const { items } = data
      const { appId } = config.body
      for (const item of items) {
        if (item.appId === appId) {
          return {
            code: '00000',
            data: 'success'
          }
        }
      }
    }
  },
  {
    url: '/accountUnlockLing/unlockMore',
    type: 'post',
    response: (_) => {
      return {
        code: '00000',
        data: 'success'
      }
    }
  }
]
